package com.yanqu.road.server.cmd.activity.huashigang;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.pb.huashigang.HuaShiGangProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.huashigang.HuaShiGangMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_HUA_SHI_GANG_ELITE_RANK, desc = "花石纲精英怪伤害奖励排行")
public class GetEliteMonsterDamageListCmd extends AbstractCommand {

    // 精英怪Y坐标
    private int y;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        HuaShiGangProto.GetEliteRankListReqMsg req = HuaShiGangProto.GetEliteRankListReqMsg.parseFrom(packet.getBytes());
        y = req.getY();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ActivityInfo activityInfo = HuaShiGangMgr.getActivityInfo();
        if (!ActivityMgr.activityInShowTime(activityInfo)) {
            ret = GameErrorCode.E_ACTIVITY_OVER_TIME;
            return;
        }

        HuaShiGangProto.CrossGetEliteRankListReqMsg.Builder builder = HuaShiGangProto.CrossGetEliteRankListReqMsg.newBuilder();
        builder.setActivityId(activityInfo.getActivityId());
        builder.setY(y);
        player.sendPacket(CrossProtocol.C2_HUA_SHI_GANG_ELITE_RANK, builder);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            HuaShiGangProto.GetEliteRankListRespMsg.Builder builder = HuaShiGangProto.GetEliteRankListRespMsg.newBuilder();
            builder.setRet(ret);
            player.sendPacket(ClientProtocol.U_HUA_SHI_GANG_ELITE_RANK, builder);
        }
    }
}
